package com.baorant.springboothelloworld.controller;

import com.baorant.springboothelloworld.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    UserService userService;

    @RequestMapping("/hello")
    public String Hello(ModelMap map, @RequestParam(value="username",required=true) String username){
        String name = userService.getNameByUsername(username);
        map.addAttribute("username", username);
        map.addAttribute("name", name);
        return "userHello";
    }
}


